package com.mashibing.controller;

import com.mashibing.internalcommon.dto.Car;
import com.mashibing.internalcommon.dto.DriverCarBindingRelationship;
import com.mashibing.internalcommon.dto.DriverUser;
import com.mashibing.internalcommon.dto.ResponseResult;
import com.mashibing.internalcommon.request.VerificationCodeDTO;
import com.mashibing.internalcommon.response.DriverUserExistsResponse;
import com.mashibing.service.DriverUserService;
import com.mashibing.service.IDriverCarBindingRelationshipService;
import lombok.extern.slf4j.Slf4j;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Slf4j
public class DriverUserController {

    @Autowired
    private DriverUserService driverUserService;

    @Autowired
    private IDriverCarBindingRelationshipService driverCarBindingRelationshipService;

    @PostMapping("/updateUser")
    public ResponseResult updateUser(@RequestBody DriverUser driverUser) {
        return driverUserService.updateUser(driverUser);
    }

    @GetMapping("/verificationDriverUser/{phoneNumber}")
    public ResponseResult<DriverUserExistsResponse> verificationDriverUser(@PathVariable String phoneNumber) {
        return driverUserService.verificationDriverUser(phoneNumber);
    }

    /**
     * 新增司机
     * @param driverUser
     * @return
     */
    @PostMapping("/addUser")
    public ResponseResult addUser(@RequestBody DriverUser driverUser){
        log.info(JSONObject.fromObject(driverUser).toString());
        return driverUserService.addDriverUser(driverUser);
    }

    /**
     * 根据司机手机号查询司机和车辆绑定关系
     * @param driverPhone
     * @return
     */
    @GetMapping("/getDriverCarRelationShip")
    public ResponseResult<DriverCarBindingRelationship> getDriverCarRelationShip(@RequestParam String driverPhone){
        return driverCarBindingRelationshipService.getDriverCarRelationShipByDriverPhone(driverPhone);
    }


}
